package com.xiaohudie.JUC;

/**
 * @Author xiao hu die
 * @Date 2022/1/13 22:21
 * @Version 1.0
 */

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArraySet;

/**hasSet线程安全*/
public class Thread06 {
    public static void main(String[] args) {
      //  Set<String> stringSet =new HashSet<>();
        Set<String> stringSet =new CopyOnWriteArraySet<>();
        for (int i = 0; i <20 ; i++) {
            new Thread(()->{
                stringSet.add(UUID.randomUUID().toString());
                System.out.println(stringSet);
            },String.valueOf(i)).start();
        }
    }

}
